import './public-path'
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom'

// const root = ReactDOM.createRoot(

//   document.getElementById('root') as HTMLElement
// );
// root.render(
//   <React.StrictMode>
//     <App />
//   </React.StrictMode>
// );

function render(props:any) {
  const { container } = props;
  const copyContainer = container ? container.querySelector('#root') : document.querySelector('#root')
  const root = ReactDOM.createRoot(copyContainer as HTMLElement)
  console.log('window.__POWERED_BY_QIANKUN__ === ',window)
  console.log('window.__POWERED_BY_QIANKUN__ === ',(window as any).__POWERED_BY_QIANKUN__)
  root.render(
    <React.StrictMode>
      <BrowserRouter basename={(window as any).__POWERED_BY_QIANKUN__ ? '/mirco-app1' : '/'}>
        <App />
      </BrowserRouter>
    </React.StrictMode>
  );
}

if (!(window as any).__POWERED_BY_QIANKUN__) {
  render({});
}

export async function bootstrap() {
  console.log('[react16] react app bootstraped');
}

export async function mount(props:any) {
  console.log('[react16] props from main framework', props);
  render(props);
}

export async function unmount(props:any) {
  // const { container } = props;
  // const copyContainer = container ? container.querySelector('#root') : document.querySelector('#root')
  // const root = ReactDOM.createRoot(copyContainer as HTMLElement)
  // root.unmount()
}

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
